<template>

  <div>

    <!--搜索框部分-->
    <el-card>

      <el-form inline label-width="90px" size="mini" class="demo-form-inline">

        <el-form-item label="名称">
          <el-input placeholder="请输入内容" v-model.trim="searchParam.name" clearable size="mini"></el-input>
        </el-form-item>

        <el-form-item label="导演">
          <el-input placeholder="请输入导演名字" v-model.trim="searchParam.director" clearable size="mini"></el-input>
        </el-form-item>

        <el-form-item label="影视类型">
          <el-select v-model="searchParam.typeId" placeholder="请选择影视类型" clearable>
            <el-option
              v-for="item in moviesType"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="评分">
          <el-select v-model="searchParam.grade" placeholder="请选择评价" clearable>
            <el-option label="☆ 浪费时间" :value="1"></el-option>
            <el-option label="☆☆ 勉强下咽" :value="2"></el-option>
            <el-option label="☆☆☆ 一般" :value="3"></el-option>
            <el-option label="☆☆☆☆ 优秀" :value="4"></el-option>
            <el-option label="☆☆☆☆☆ 优质" :value="5"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="是否追更">
          <el-select v-model="searchParam.continueSee" placeholder="请选择是否追更" clearable>
            <el-option label="已终止观影" value="1"></el-option>
            <el-option label="继续追更" value="2"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="观看进度">
          <el-select v-model="searchParam.speedOfProgress" placeholder="请选择观影进度" clearable>
            <el-option label="计划中  (准备看)" value="1"></el-option>
            <el-option label="观影中断(不会继续追)" value="2"></el-option>
            <el-option label="观影暂停(停止观影后续会继续)" value="3"></el-option>
            <el-option label="观影完成(完整的看完了)" value="9"></el-option>
          </el-select>
        </el-form-item>


        <el-form-item>
          <el-button type="primary" size="mini" @click="getMoviesPageBefore">查询</el-button>
          <el-button type="warning" size="mini" @click="resetQueryMovies">重置</el-button>
          <el-button type="warning" size="mini" @click="openSaveMovies">新增</el-button>
        </el-form-item>

      </el-form>

    </el-card>


    <!--列表部分-->
    <el-card class="box-card">

      <div style="height: 610px; max-height: 610px;">

        <div v-if="moviesList === undefined || moviesList == null || moviesList.length <= 0">
          <!--为空的时候展示图片-->
          <el-row>
            <el-col :span="24">
              <div style="display:flex; justify-content: center">
                <img src="@/assets/images/collect/sunset-glow.jpg" alt=""/>
              </div>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <div style="text-align:center; font-size:14px">
                <div>你要尽全力保护你的梦想，那些嘲笑你的人，他们必定会失败，他们想把你变成和他们一样的人。如果你有梦想的话，就要努力去实现。——《当幸福来敲门》</div>
                <div>我喜欢一个人，想给她一个好结局。——《少年的你》</div>
                <div>我们需要改变，你和我。——《莫里斯》</div>
                <div>说的是一辈子，差一年，一个月，一天，一个时辰都不是一辈子。—— 《你好旧时光》</div>
                <div>不顾家庭的男人不是真正的男人！ ——《教父》</div>
                <div>上天没有给你想要的，不是因为你不配，而是你值得拥有更好的。——《乱世佳人》</div>
                <div>孩子们，及时行乐，把握今天。——《死亡诗社》</div>
              </div>
            </el-col>
          </el-row>
        </div>

        <div v-else>
          <!--
            gutter	栅格间隔，属性来指定每一栏之间的间隔
            type	布局模式，可选 flex，现代浏览器下有效
          -->
          <el-row :gutter="10"  class="el-row">
            <!--span 栅格占据的列数,默认 24-->
            <el-col :span="6" v-for = "(movies,index) in moviesList" :key="movies.id" class="el-col" >

              <!--一本书的样式-->
              <el-card :key="index" >

                <el-row>
                  <el-col :span="9">
                    <el-image v-if="movies.icoPath != null" class="moviesImage" fit="contain" :src="movies.icoPath"></el-image>
                    <el-image v-else class="moviesImage" fit="contain" :src="require('@/assets/images/collect/Film.png')"></el-image>
                  </el-col>

                  <el-col :span="15">
                    <div class="moviesAuthor hand" style="font-weight: 600;" @click="toOpenMoviesDetailed(movies)">{{movies.name | ellipsis20}}</div>
                    <div class="moviesAuthor moviesAuthorColor">导演：{{movies.director | ellipsis20}}</div>
                    <div class="moviesAuthor moviesAuthorColor">类型：{{movies.moviesTypeName | ellipsis20}}</div>
                    <div class="moviesAuthor moviesAuthorColor">评分：</div>
                    <el-rate class="moviesAuthor" disabled v-model="movies.grade"></el-rate>
                  </el-col>
                </el-row>

                <el-row>
                  <!--<el-col :span="24">-->
                  <!--  <span class="moviesAuthor">简介：</span>-->
                  <!--  <p class="briefIntroduction hand" @click="toOpenMoviesDetailed(movies)">{{movies.describe | ellipsis60}}</p>-->
                  <!--</el-col>-->
                  <el-col :span="24">
                    <span class="moviesAuthor">点评：</span>
                    <p class="briefIntroduction hand" @click="toOpenMoviesDetailed(movies)">{{movies.comment | ellipsis60}}</p>
                  </el-col>
                </el-row>

              </el-card>
            </el-col>

          </el-row>
        </div>

      </div>

      <!--分页部分-->
      <el-pagination
        style="width:33%; margin-right:10px; "
        background
        layout="total, prev, pager, next, jumper"
        @current-change="moviesPageCurrentChange"
        :page-size="pageConfig.size"
        :current-page="pageConfig.current"
        :pager-count="5"
        :total="pageConfig.total">
      </el-pagination>
    </el-card>

    <MoviesDetailed ref="moviesDetailedRef" @getMoviesPage="getMoviesPage" @openUpdMovies="openUpdMovies"></MoviesDetailed>
    <MoviesSaveUpd ref="moviesSaveUpdRef" @getMoviesPage="getMoviesPage" ></MoviesSaveUpd>

  </div>

</template>

<script>

  import MoviesDetailed from './MoviesDetailed.vue'
  import MoviesSaveUpd from './MoviesSaveUpd.vue'
  import http from '@/utils/http'

  export default {
    name: "MoviesList",
    components:{
      MoviesDetailed,
      MoviesSaveUpd,
    },
    data(){
      return {
        // 分页参数
        pageConfig: {
          // 每页记录数
          size: 8,
          // size: 32,
          // 当前页码
          current: 1,
          // 总记录数
          total: 0,
        },
        // 查询参数
        searchParam: {
          name: null,
          director: null,
          toStar: null,
          speedOfProgress: null,
          grade: null,
          continueSee: null,
          typeId: null,
        },
        // 影视类型
        moviesType: [],
        // 影视列表
        moviesList: [],
      }
    },
    /**
     * 过滤器
     */
    filters: {
      /**
       * 数据超过长度显示省略号
       * @param value
       * @return {string|*}
       */
      ellipsis60(value) {
        if (!value) return "";
        if (value.length > 110) {
          return value.slice(0, 110) + "...";
        }
        return value;
      },
      /**
       * 数据超过长度显示省略号
       * @param value
       * @return {string|*}
       */
      ellipsis20(value) {
        if (!value) return "";
        if (value.length > 20) {
          return value.slice(0, 20) + "...";
        }
        return value;
      },
    },
    methods: {
      /**
       * 打开详情
       * @param obj 要查看的对象
       */
      toOpenMoviesDetailed(obj){
        this.$refs.moviesDetailedRef.openMoviesDetailed(obj)
      },
      /**
       * 打开更新
       * @param obj 要更新的数据
       */
      openUpdMovies(obj){
        this.$refs.moviesSaveUpdRef.openMoviesPage('upd', obj, this.moviesType)
      },
      /**
       * 打开影视添加
       */
      openSaveMovies(){
        this.$refs.moviesSaveUpdRef.openMoviesPage('save', null, this.moviesType)
      },
      /**
       * 分页被改变的时候
       * @param value 当前页
       */
      moviesPageCurrentChange(value){
        this.pageConfig.current = value
        this.getMoviesPage()
      },
      /**
       * 重置查询
       */
      resetQueryMovies(){
        this.searchParam = {
          name: null,
          director: null,
          toStar: null,
          speedOfProgress: null,
          grade: null,
          continueSee: null,
          typeId: null,
        }
      },
      /**
       * 获取影视类型
       */
      getMoviesType(){
        http.get("/movies/getMoviesType", {}).then(response => {
          let res = response.data;
          if (res.status === 'error'){
            // 401是token过期跳转的
            if (res.code !== 401){
              this.$message.error(res.msg);
            }
            return
          }

          this.moviesType = res.data

        }).catch(error => {
          this.$message.error(error.message);
        })
      },
      /**
       * 查询前重置分页参数
       */
      getMoviesPageBefore(){
        this.pageConfig.current = 1
        this.getMoviesPage()
      },
      /**
       * 分页查询影视信息
       */
      getMoviesPage(){
        this.searchParam.current = this.pageConfig.current
        this.searchParam.size = this.pageConfig.size

        http.post("/movies/getMoviesPage", this.searchParam).then(response => {
          let res = response.data;
          if (res.status === 'error'){
            // 401是token过期跳转的
            if (res.code !== 401){
              this.$message.error(res.msg);
            }
            return
          }
          // 分页数据
          let data = res.data;
          this.pageConfig.total = data.total;
          this.pageConfig.current = data.current;
          this.pageConfig.size = data.size;
          // 处理数据
          this.moviesList = data.records

        }).catch(error => {
          this.$message.error(error.message);
        })
      },
    },
    mounted(){
      this.$store.commit('navigationListChange', ['我的收藏', '影视'])
      this.getMoviesPage()
      this.getMoviesType()
    }
  }
</script>

<style scoped>

  /*让card进行浮动*/
  .el-row {
    /*margin-bottom: 10px;*/
    display: flex;
    flex-wrap: wrap
  }

  /*简介*/
  .briefIntroduction{
    height: 42px;
    max-height: 42px;
  }

  /*card之间的高*/
  .el-col {
    border-radius: 4px;
    align-items: stretch;
    margin-bottom: 5px;
  }

  /*图片列表框*/
  .box-card {
    /*width: 100%;*/
    max-height: 670px;
    height: 670px;
    margin-top: 10px
  }

  /*影视图片样式*/
  .moviesImage {
    width: 102px;
    height: 136px
  }

  /*名称部分的样式*/
  .moviesAuthor{
    width: 150px;
    /*width: 180px;*/
    margin-top: 12px;
    /*文字超长隐藏*/
    overflow:hidden;
  }

  /*书籍字体颜色*/
  .moviesAuthorColor {
    color: #909399;
  }

  .hand{
    /*变手*/
    cursor:pointer;
  }

</style>
